-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure we handle the scenario the payment service code expects there to be an active span but finds none #2129
base: main
Are you sure you want to change the base?
Conversation
@pichlermarc I would love to hear your opinion here |
I understand if the SDK is disabled, the service should not throw an error which is what #2124 discusses. I struggle to understand in what scenario we need to start a trace if one does not exists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I struggle to understand in what scenario we need to start a trace if one does not exists.
I agree - in my opinion the way to address the problem of the crashing app would be either to:
- optional chain on the span object obtained via
getActiveSpan()
wherever it's used- example:
span.setAttributes({...})
->span?.setAttributes({...})
- example:
- create and end an internal span always no matter if a trace was already started or not to which you can attach any attributes and errors you like, while retaining semantics for the grpc span that's likely being modified here (since that one is strictly supposed to follow the gRPC semconv anyway and modifying error status may interfere with that).
src/payment/index.js
Outdated
@@ -4,12 +4,22 @@ const grpc = require('@grpc/grpc-js') | |||
const protoLoader = require('@grpc/proto-loader') | |||
const health = require('grpc-js-health-check') | |||
const opentelemetry = require('@opentelemetry/api') | |||
const tracer = opentelemetry.trace.getTracer(process.env.OTEL_SERVICE_NAME); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
process.env.OTEL_SERVICE_NAME
may be undefined
, which is not a valid name for the tracer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thanks understood. I have switched to optional chain as suggested above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I guess I misundertood a little - Should we create the internal span? I think this makes more sense as we retain the original semantics
I am proposing a very minor change to handle when auto-instrumentation is disabled( similar to #2124 ) for the payment service. In this scenario, an exception is raised but I would expect it to be handled gracefully.
Changes
Added some very simple logic to check if the current active span is undefined, if it is we create a new span & mark this as the active span.
Merge Requirements
For new features contributions, please make sure you have completed the following
essential items:
CHANGELOG.md
updated to document new feature additionsMaintainers will not merge until the above have been completed. If you're unsure
which docs need to be changed ping the
@open-telemetry/demo-approvers.